package com.example.hls_homework2;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class UC1Activity extends AppCompatActivity {

    private LinearLayout layoutContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc1);

        layoutContainer = findViewById(R.id.layout_container);
        Button btnHorizontal = findViewById(R.id.btn_horizontal);
        Button btnVertical = findViewById(R.id.btn_vertical);
        Button btnLeft = findViewById(R.id.btn_left);
        Button btnBack = findViewById(R.id.btn_back);

        btnHorizontal.setOnClickListener(v -> {
            layoutContainer.setOrientation(LinearLayout.HORIZONTAL);
            updateButtonTexts();
        });

        btnVertical.setOnClickListener(v -> {
            layoutContainer.setOrientation(LinearLayout.VERTICAL);
            updateButtonTexts();
        });

        btnLeft.setOnClickListener(v -> {
            layoutContainer.setOrientation(LinearLayout.VERTICAL);
            layoutContainer.setGravity(android.view.Gravity.LEFT);
            updateButtonTexts();
        });

        btnBack.setOnClickListener(v -> finish());
    }

    private void updateButtonTexts() {
        for (int i = 0; i < layoutContainer.getChildCount(); i++) {
            View child = layoutContainer.getChildAt(i);
            if (child instanceof Button) {
                ((Button) child).setText("按钮 " + (i + 1));
            }
        }
    }
}